#ifndef T_MY_HTTPBACKEND_P_H
#define T_MY_HTTPBACKEND_P_H

#include "t_httpnetworkconnection_p.h"
#include "private/qnetworkaccessbackend_p.h"

#include "nam.h"

class T_MyHttpBackend: public QNetworkAccessBackend
{
    Q_OBJECT
public:
	T_MyHttpBackend();
	virtual ~T_MyHttpBackend();

    virtual void open();
    virtual void closeDownstreamChannel();
    virtual bool waitForDownstreamReadyRead(int msecs);

    virtual void downstreamReadyWrite();
    virtual void setDownstreamLimited(bool b);

    virtual void copyFinished(QIODevice *);

    // we return true since HTTP needs to send PUT/POST data again after having authenticated
	virtual bool needsResetableUploadData() { return true; }

private slots:
	void finished(); // override
	void authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator);
	void replyReadyRead();
    void replyFinished();
    void replyHeaderChanged();
	void replyError(QNetworkReply::NetworkError errorCode);

private:
	NetworkAccessManager m_nam;
	QNetworkReply *m_networkReply;

	void p_disconnectFromHttp();
	void p_readFromHttp();
	void p_checkForRedirect(const int statusCode);
};

#endif
